import React from "react";
import userimg from "../../assets/11.jpg";
import "./email.css";
import { Button, Form, Input, Toast } from "antd-mobile";
import { improve } from "store/login";
import { useDispatch } from "react-redux";

const Index = () => {
  const [form] = Form.useForm();
  const dispatch = useDispatch<any>();
  const Email = () => {
    const getemail = form.getFieldValue("email");
    const sessionId = localStorage.getItem("sessionId");
    const userId = localStorage.getItem("userId");

    const data = {
      userId: userId,
      sessionId: sessionId,
    };

    const email = {
      email: getemail,
    };
    dispatch(improve({ data, email })).then((res: any) => {
      if (res) {
        if (res.payload.status === "0000") {
          Toast.show({
            icon: "error",
          });
        }
      }
    });
    // console.log(data);
    // console.log(email);
  };

  return (
    <div className="Email">
      <div className="email-top">
        <h2>完善信息</h2>
        <img src={userimg} alt="" />
        <Form layout="horizontal" className="email-inp" form={form}>
          <Form.Item name={"email"}>
            <Input type="text" placeholder="请输入邮箱账号" />
          </Form.Item>
        </Form>
      </div>
      <div className="email-btn">
        <Button block size="middle" onClick={Email}>
          完成
        </Button>
      </div>
    </div>
  );
};
export default Index;
